﻿var WIDGETS = WIDGETS || {};

WIDGETS["menu-play-completed"] = function ($element) {

    var proto = {
        $element: $($element),
        $btnTime: $(),

        init: function () {
            this.discoverChildren();
            this.bindEvents();
            this.storeSelf();
        },

        discoverChildren: function () {
            this.$difficulty = this.$element.find(".completed-difficulty");
            this.$time = this.$element.find(".completed-time");
        },

        bindEvents: function () {
            EVENTBROKER.matchTopic.on(TOPIC_EVENTS.matchCompleted, this.onMatchCompleted.bind(this));
        },

        storeSelf: function () {
            this.$element.data("menu-play-completed", this);
        },

        onMatchCompleted: function (ev, matchModel) {
            this.$difficulty.text(Resx.get(matchModel.difficulty));
            var timeStr = UTIL.string.toHMM(matchModel.elapsedTime);
            this.$time.text(timeStr);
        }
    }

    proto.init();

    return proto;
}
